<?php
session_start();
include_once "login.php";

if (!isset($_SESSION['userid'])) {
  echo "<br>DEBE INICIAR SESION";
}else{
//muestro el contenido que se debe
?>

<?php $codHabEnv = $_POST['codhabenv']; ?>
<?php $ced = $_SESSION['userid']; ?>

<!DOCTYPE html>
<html>
<head>
<title>Reserva</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<link rel="stylesheet" type="text/css" href="codebase/dhtmlxcalendar.css"/>
<script src="codebase/dhtmlxcalendar.js"></script>

<style>
		input#date_from, input#date_to {
			font-family: Tahoma;
			font-size: 12px;
			background-color: #fafafa;
			border: #c0c0c0 1px solid;
			width: 100px;
		}
		span.label {
			font-family: Tahoma;
			font-size: 12px;
		}
</style>

<style type="text/css" media="screen">
.reserva input[type=text],
.reserva input[type=password],
.reserva input[type=email],
.reserva input[type=date],
.reserva input[type=datetime],
.reserva input[type=datetime-local],
.reserva input[type=number],
.reserva input[type=search],
.reserva input[type=tel],
.reserva select{
padding: 8px;
display:inline-block;
border:1px solid #555;
font-size:0.7em;
background-color: transparent;
box-shadow: inset 0 0 8px #BABABA;
border-radius:4px;
-webkit-transition:.3s linear border;
-moz-transition:.3s linear border;
-ms-transition:.3s linear border;
-o-transition:.3s linear border;
transition:.3s linear border;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box
}

</style>


<script>
		var myCalendar;
		function doOnLoad() {
			myCalendar = new dhtmlXCalendarObject(["date_from","date_to"]);
			myCalendar.setDate("2013-02-12");
			myCalendar.hideTime();
			// init values
			var t = new Date();
			byId("date_from").value = "";
			byId("date_to").value = "";
		}
		
		function setSens(id, k) {
			// update range
			if (k == "min") {
				myCalendar.setSensitiveRange(byId(id).value, null);
			} else {
				myCalendar.setSensitiveRange(null, byId(id).value);
			}
		}
		function byId(id) {
			return document.getElementById(id);
		}
</script>


</head>


<body onload="doOnLoad();">
<div align="center">

<?php
// generamos la clave aleatorea no repetida para las reservaciones
function gen_chars_no_dup($long){
  $chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";  
  mt_srand((double)microtime()*1000000);   
  $i=0;  
  while ($i != $long){  
    $rand = mt_rand() % strlen($chars);  
    $tmp = $chars[$rand];  
    $pass = $pass . $tmp;  
    $chars=str_replace($tmp, "", $chars);  
    $i++;  
  }  
  return strrev($pass);  
}
$codR = gen_chars_no_dup(8);
?>

<?php
// verificamos de que el hotel este en la tabla habitaciones
$habitacion = mysql_query("SELECT * FROM  `Habitaciones` WHERE  `codHotHab` LIKE  '$codHabEnv'");
//Mostramos los registros
while ($row1=mysql_fetch_array($habitacion)){
  $ch = $row1['codHotHab'];
}
mysql_free_result($habitacion)
?>


<!-- creando el formulario para el anvio de la informacion -->
<form method="post" name="reserva" action="env_rsv.php" class="reserva">

<input type="hidden" name="codRes" value="<?php echo $codR ?>">
<input type="hidden" name="codHot" size="12" maxlength="10" value="<?php echo $ch ?>">
<input type="hidden" name="nroCed" size="12" maxlength="10" value="<?php echo $ced ?>">
<span>Fecha llegada: </span><input type="text" name="fechaLlegada" placeholder="0000-00-00" id="date_from" onclick="setSens('date_to', 'max');" readonly="true"><br><br>
<span>Fecha Salida: </span><input type="text" name="fechaSalida" placeholder="0000-00-00" id="date_to" onclick="setSens('date_from', 'min');" readonly="true"><br><br>

<h3><div align="center">Habitaciones [disponibles]</div></h3>

<?php
$habitacion = mysql_query("SELECT * FROM `Habitaciones` WHERE `codHotHab` LIKE '$codHabEnv' AND `estado` = 'disponible'");
// mostramos los registros de las habitaciones que tiene disponible ese hotel
echo "<table align=\"center\" border=\"1\">";
echo "<tr><td>Tipo de Habitacion</td><td>Nro de Habitacion</td><td>Seleccionar</td></tr>";
while ($h=mysql_fetch_array($habitacion)){
  $nh = $h['nroHab'];
  $th = $h['tipo'];
  echo "<tr><td>".$th."</td><td>".$nh."</td><td><input type=\"radio\" name=\"nroHabRes\" value=\"$nh\"></td></tr>";
}
echo "</table>";
mysql_free_result($habitacion)
?>
<br>
<input type="submit" value="Enviar" >
</form>



</div></body></html>

<?php
} 
?>


